package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Retaildetails;
import com.restaurant.service.RetaildetailsService;

public class RetaildetailsServiceImpl implements RetaildetailsService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Retaildetails addOrModify( Retaildetails objRetaildetails ) {
       return ( Retaildetails ) hibernateTemplate.merge( objRetaildetails );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Retaildetails deleteRecord( Retaildetails objRetaildetails ) {
       hibernateTemplate.delete( objRetaildetails );
       return objRetaildetails;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Retaildetails modifyRecord( Retaildetails objRetaildetails ) {
       return ( Retaildetails ) hibernateTemplate.merge( objRetaildetails );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Retaildetails> loadAll() {
       return (List<Retaildetails>)hibernateTemplate.findByNamedQuery( "Retaildetails.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Retaildetails loadByPrimaryKey( Long primaryKey ) {
       return (Retaildetails) hibernateTemplate.get( Retaildetails.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Retaildetails deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Retaildetails> loadByHql(String query) {
       return ( List<Retaildetails> ) hibernateTemplate.find( query );
   }
}